home *** CD-ROM | disk | FTP | other *** search
/ Scene Storm / Scene Storm - Volume 1.iso / coding / asm / misc / execports / putmsg.s < prev    next >
Text File  |  1992-09-02  |  4KB  |  128 lines

  1. ;==============================================================[ Description ]=
  2.  
  3. ;    This is an example of source containing Exec's _LVOPutMsg() routine,
  4. ;    which you can use to put a message to a port.
  5. ;    In this case, program looks for port called "Amsterdam" (or anything
  6. ;    you want 8), and if it finds, then send a message. You should earlier
  7. ;    run another source, that creates port "Amsterdam" (it's WaitPort.s).
  8. ;    You can type some texts after PutMsg program (as parameters) and the
  9. ;    task waiting for this message will print it on the console.
  10.  
  11. ;    $VER: PutMsg.s V1.1 (30.10.94)
  12. ;    Source by Cromax of Alchemy (kita@sun10.ci.pwr.wroc.pl)
  13.  
  14. ;===================================================================[ Values ]=
  15.  
  16. ExecBase        Equ    4
  17.  
  18. _LVOFindTask        Equ    -294
  19. _LVOFindPort        Equ    -390
  20. _LVOForbid        Equ    -132
  21. _LVOPermit        Equ    -138
  22. _LVOPutMsg        Equ    -366
  23. _LVOWaitPort        Equ    -384
  24.  
  25. NT_MSGPORT        Equ    4
  26. NT_MESSAGE        Equ    5
  27.  
  28. lh_TailPred        Equ    008
  29.  
  30. mp_SigTask        Equ    016
  31. mp_MsgList        Equ    020
  32.  
  33. mymsg_Length        Equ    4        ; Offsets of our message
  34. mymsg_String        Equ    8        ; defined by myself
  35.  
  36. ;=============================================================[ Main Program ]=
  37.  
  38.         Section    PutMessage,Code_P
  39.  
  40. Begin:        bra.s    .Skip
  41.  
  42.         dc.b    "$VER: PutMsg V1.1 (30.10.94)",10,0
  43.         even
  44.  
  45. .Skip:        lea    Message,a1
  46.         adda.l    #20,a1            ; Fill our message structure
  47.         move.l    d0,mymsg_Length(a1)    ; with length of parameter
  48.         move.l    a0,mymsg_String(a1)    ; string and pointer to it
  49.  
  50.         movea.l    [ExecBase].w,a6        ; I'm not quiet sure you have
  51.         jsr    _LVOForbid(a6)        ; to use Forbid/Permit here...
  52.  
  53.         movea.l    [ExecBase].w,a6        ; Find pointer to Task
  54.         suba.l    a1,a1            ; structure of our task
  55.         jsr    _LVOFindTask(a6)    ; (if a1=NULL)
  56.         move.l    d0,_Task
  57.         beq.w    Permit
  58.  
  59.         lea    MsgPort,a0        ; Complete MsgPort structure
  60.         move.l    d0,mp_SigTask(a0)    ; If we didn't found anything
  61.         adda.l    #mp_MsgList,a0        ; Set pointers of List struct
  62.         move.l    a0,lh_TailPred(a0)    ; in MsgPort structure
  63.         addq    #4,a0            ; Get addres of lh_Tail
  64.         clr.l    (a0)            ; Clear lh_Tail
  65.         move.l    a0,-(a0)        ; Address of lh_Tail to lh_Head
  66.  
  67.         movea.l    [ExecBase].w,a6        ; If you want to put a message
  68.         lea    DestPortName,a1        ; to a public port, then here
  69.         jsr    _LVOFindPort(a6)    ; we'll find its address using
  70.         move.l    d0,_DestinyPort        ; its name
  71.         beq.s    Permit            ; If port doesn't exist, then
  72.                         ; quit
  73.         movea.l    [ExecBase].w,a6        ; In a0 we place address of
  74.         movea.l    d0,a0            ; MsgPort to send a message to
  75.         lea    Message,a1        ; (if port isn't public, we
  76.         jsr    _LVOPutMsg(a6)        ; have to know its address
  77.                         ; earlier)
  78. Permit:        movea.l    [ExecBase].w,a6        ; Enable multitaksing...
  79.         jsr    _LVOPermit(a6)
  80.  
  81.         tst.l    _DestinyPort
  82.         beq.s    End
  83.         movea.l    [ExecBase].w,a6        ; Wait for reply message...
  84.         lea    MsgPort,a0
  85.         jsr    _LVOWaitPort(a6)
  86.  
  87. End:        moveq    #0,d0
  88.         rts
  89.  
  90. ;=====================================================================[ Data ]=
  91.  
  92.         Section    Data,Data_P
  93.  
  94. MsgPort:    dc.l    0        ; ln_Succ
  95.         dc.l    0        ; ln_Pred
  96.         dc.b    NT_MSGPORT    ; ln_Type
  97.         dc.b    0        ; ln_Pri
  98.         dc.l    0        ; ln_Name
  99.         dc.b    0        ; mp_Flags
  100.         dc.b    0        ; mp_SigBits
  101.         dc.l    0        ; mp_SigTask
  102.         dc.l    0        ; lh_Head
  103.         dc.l    0        ; lh_Tail
  104.         dc.l    0        ; lh_TailPred
  105.         dc.b    0        ; lh_Type
  106.         dc.b    0        ; lh_pad
  107.  
  108. Message:    dc.l    0        ; ln_Succ
  109.         dc.l    0        ; ln_Pred
  110.         dc.b    NT_MESSAGE    ; ln_Type
  111.         dc.b    0        ; ln_Pri
  112.         dc.l    0        ; ln_Name
  113.         dc.l    MsgPort        ; mn_ReplyPort
  114.         dc.w    32        ; mn_Length (20b + 12b of our msg)
  115.         ;······················    ; Here begins our message
  116.         dc.l    "CRMX"        ; mymsg_IDHeader
  117.         dc.l    0        ; mymsg_Length
  118.         dc.l    0        ; mymsg_String
  119.  
  120. DestPortName:    dc.b    "Amsterdam",0
  121.  
  122. ;=====================================================================[ Vars ]=
  123.  
  124.         Section    Vars,Bss
  125.  
  126. _DestinyPort:    ds.l    1
  127. _Task:        ds.l    1
  128.